package com.zxl.live.screen.call.helper;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

import com.zxl.live.screen.call.tools.Utils;
import com.zxl.live.tools.common.ApplicationHelper;
import com.zxl.live.tools.guide.BasePermissionGuide;
import com.zxl.live.tools.guide.CustomToast;
import com.zxl.live.tools.tools.AppUtils;

/**
 * Created by Administrator on 2017/9/18.
 */
public class NotificationPermissionGuide extends BasePermissionGuide {

    private CustomToast mToast;

    public NotificationPermissionGuide(Context mContext, Class mStartActivityCls) {
        super(mContext, mStartActivityCls);
    }

    @Override
    public boolean havePermission() {
        return Utils.isNotifyPermissionEnable();
    }

    @Override
    public void startMonitor() {
        super.startMonitor();
        Utils.gotoGrantAccessibility(mContext);
        ApplicationHelper.postThreadDelayed(new Runnable() {
            @Override
            public void run() {
                showUsageToast();
            }
        }, 200);
    }

    @Override
    public void stopMonitor() {
        super.stopMonitor();
        if (null != mToast) {
            mToast.dismiss();
        }
    }

    private void showUsageToast() {
        mToast = new CustomToast();
        mToast.setToastSize(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        mToast.setWindowAnim(com.zxl.live.tools.R.style.toast_guide_permission);
        View view = LayoutInflater.from(ApplicationHelper.getContext()).inflate(com.zxl.live.tools.R.layout.toast_permission_alert_setting, null, false);
        ((ImageView) view.findViewById(com.zxl.live.tools.R.id.iv_icon)).setImageDrawable(AppUtils.getAppIcon(mContext, mContext.getPackageName()));
        view.findViewById(com.zxl.live.tools.R.id.iv_close).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mToast.dismiss();
            }
        });
        mToast.setGravity(Gravity.BOTTOM);
        mToast.setShowToastDuration(5000);
        mToast.setContentView(view);
        mToast.show();
    }

}
